#include "exceptions.h"
#include "files.h"
#include "files_check.h"

namespace torrent {

FilesCheck::List FilesCheck::m_checks;

FilesCheck::FilesCheck(Files* f, Service* s, int arg) :
	m_position(0),
	m_files(f),
	m_service(s),
	m_arg(arg){
}

FilesCheck::~FilesCheck() {
}

void FilesCheck::check(Files* f, Service* s, int arg) {
	for (List::iterator it = m_checks.begin(); it != m_checks.end(); ++it) {
		if ((*it)->m_files == f) {
			throw internal_error("FilesCheck::check received a Download thas is already being checked");
		}
	}

	m_checks.push_back(new FilesCheck(f, s, arg));

	if (m_checks.size() == 1)
		m_checks.front()->insertService(Timer::current(), 0);
}

} // namespace torrent
